<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>资生堂企业后台管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<link rel="stylesheet" href="../../static/css/font-awesome-4.7.0/css/font-awesome.min.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
		<style>
			.layui-table-cell {
				height: 60px;
				line-height: 60px;
			}
			select {
				width: 150px;
				color: #666;
				height: 38px;
				line-height: 1.3;
				border: 1px solid #e6e6e6;
				background-color: #fff;
				border-radius: 2px;
				padding-left: 5px;
			}
		</style>
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
	        <a href="">客户管理</a>
	        <a>
	          <cite>客户列表</cite></a>
        </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-body">
			<div class="weadmin-block">
				<div class="layui-inline">
					<input type="text" id="customer_search_keyword" name="keyword" placeholder="客户昵称/BC姓名" autocomplete="off" class="layui-input">
				</div>
				<div style="margin-left:30px;" class="layui-inline">
					<select id="customer_search_type" class="valid">
						<option value="1">按客户昵称搜索</option>
						<option value="2">按客户昵称搜索</option>
						<option value="3">按会员姓名搜索</option>
						<option value="4">按手机号搜索</option>
						<option value="5">按所属BC搜索</option>
						<option value="6">按所属门店搜索</option>
					</select>
				</div>
				<button style="margin-left:30px;"  class="layui-btn" onclick="customerSearch()" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
				<button style="margin-left:30px;"  class="layui-btn" onclick="sync()" lay-filter="sreach">刷新</button>
				<span class="fr" style="line-height:40px"></span>
			</div>
			<!--  用户表格 -->
			<table class="layui-table" lay-filter="customer_table" id="customer_table" style="margin: 0"></table>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/jquery-1.8.0.min.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js" charset="utf-8"></script>
		<script>
			layui.use(['table'], function() {
				var table = layui.table;
				// 加载用户数据表格
				window.customerTable = table.render({
					id: 'customerTable',
					elem: '#customer_table',
					url: commonUtil.domain() + '/admin/wxwork/customer/list?followBc=true', //数据接口
					method: 'post',
					page: true, //开启分页
					request: {
						pageName: 'pageNum', // 分页当前页数发给后台的参数名
						limitName: 'pageSize', // 分页每页多少条发给后台的参数名
						countName: 'total'
					},
					done: function(res) {
						$('.layui-laypage-count').text('共' + res.total + '条')
					},
					cols: [
						[ //表头
							{
								field: 'name',
								title: '客户备注名/微信昵称',
								width: 120
							} , {
								field: 'avatar',
								title: '会员',
								width: 80,
								templet: '#avatar'
							}, {
								field: 'followBcName',
								title: '会员ID',
								width: 80
							}, {
								field: 'followBcCode',
								title: '会员姓名',
								width: 80
							}, {
								field: 'remark',
								title: '手机号',
								width: 80
							},  {
								field: 'unionId',
								title: '兑换编号',
								width: 80,
								templet: '#avatar'
							}, {
								field: 'followBcName',
								title: '兑换产品',
								width: 80
							}, {
								field: 'followBcCode',
								title: '兑换数量',
								width: 80
							},  {
								field: 'followBcCode',
								title: '兑换方式',
								width: 80
							},  {
								field: 'followBcCode',
								title: '兑换门店',
								width: 80
							},  {
								field: 'followBcCode',
								title: '申领状态',
								width: 80
							},  {
								field: 'followBcCode',
								title: '申请日期',
								width: 80
							},  {
								field: 'followBcCode',
								title: '更新时间',
								width: 80
							},  {
								field: 'remark',
								title: 'BC ID',
								width: 80
							}, {
								field: 'status',
								title: '所属BC',
								width: 100,
								templet: '#status'
							}, {
								field: 'gender',
								title: '门店编号',
								width: 60,
								templet: '#gender'
							} ,
							{
								field: 'gender',
								title: '所属门店',
								width: 60,
								templet: '#gender'
							} , {
								field: 'oper',
								title: '操作',
								width: 80,
								templet: '#oper'
							}
						]
					]
				});
				// 刷新表格
				customerTable.refresh = function(data) {
					customerTable.reload({
						where: data,
						page: {
							curr: 1 // 重新从第 1 页开始
						}
					});
				}
				// 搜索按钮
				window.customerSearch = function(res) {
					var data = {};
					var keyword = $("#customer_search_keyword").val();
					// 先检查当前keyword需要匹配bc名称还是匹配客户的名称
					var searchType = $("#customer_search_type").val();
					if(searchType == 1) {
						// 按照客户昵称搜索
						data.keyword = keyword
					} else if(searchType == 2) {
						data.bcKeyword = keyword
					}
					// 传入搜索条件 重载表格
					customerTable.refresh(data);
				}
				// 搜索按钮
				window.customerSearch = function(res) {
					var data = {};
					var keyword = $("#customer_search_keyword").val();
					// 先检查当前keyword需要匹配bc名称还是匹配客户的名称
					var searchType = $("#customer_search_type").val();
					if(searchType == 1) {
						// 按照客户昵称搜索
						data.keyword = keyword
					} else if(searchType == 2) {
						data.bcKeyword = keyword
					}
					// 传入搜索条件 重载表格
					customerTable.refresh(data);
				}
				
				// 同步按钮
				window.sync = function(res) {
					layer.confirm('刷新客户的昵称，头像等信息', function(index) {
						var ajaxParam = {
								url : commonUtil.domain() + '/admin/wxwork/customer/sync'
							}
						ajaxUtil.post(ajaxParam, function(data) {
							if (data.code == 200) {
								layer.alert("刷新成功");
								customerTable.refresh();
							} else {
								layer.alert(data.msg);
							}
						});
					});
				}
				// 监听表格点击删除和修改按钮
				table.on('tool(customer_table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
					var data = obj.data; // 获得当前行数据
					var externalId = data.externalId;
					var name = data.name;
					var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
					var tr = obj.tr; // 获得当前行 tr 的DOM对象
					if(layEvent == 'transfer') {
						// 显示员工列表
						WeAdminShow('转交BC', './customer-add.html?externalId=' + externalId + "&externalName=" + name)
					}else if(layEvent == "unbind"){
						layer.confirm('确定要将客户"' + name + '"解绑吗?', function(res){
							// 发送ajax解绑
							var ajaxParam = {
									url : commonUtil.domain() + '/admin/wxwork/customer/unbind',
									data : {
										externalId : externalId
									}
								}
							ajaxUtil.post(ajaxParam, function(data) {
								if (data.code == 200) {
									layer.alert("解绑成功", {
										icon : 6
									}, function() {
										customerTable.refresh();
										layer.closeAll();
									});
								} else {
									layer.alert(data.msg);
								}
							});
						});
					}
				});
			});
		</script>
		<script>
			$(function(){
				commonUtil.setMaxLength(40);
			})
		</script>
		<script type="text/html" id="avatar">
			<img width="60" height="60" src="{{ d.avatar }}" alt="无图" />
		</script>
		<script type="text/html" id="followUser">
			{{#  for(var i = 0; i < d.followUserList.length; i++){ }}
				{{#  if(d.followUserList[i].name != null){ }}
					{{ d.followUserList[i].name + "(" + d.followUserList[i].staffCode + ");" }}
				{{#  } }}
			{{#  } }}
		</script>
		<script type="text/html" id="gender">
			{{# if(d.gender == 1){ }}
			<i style="color:#1296db" class="layui-icon">&#xe662;</i> {{# } else { }}
			<i style="color:#FF9E9E" class="layui-icon">&#xe661;</i> {{# } }}
		</script>
		<script type="text/html" id="oper">
			<a lay-event="transfer" title="转交"><i style="display: inline-block; width: 16px; height: 16px; margin-right: 5px; background: url(../../static/images/transfer.png); background-size: 100% 100%;" class="layui-icon"></i></a>
			<a lay-event="unbind" title="解绑"><i style="display: inline-block; width: 16px; height: 16px; background: url(../../static/images/unbind.png); background-size: 100% 100%;"  class="layui-icon"></i></a>
		</script>
	</body>

</html>